// Nodes.cpp : Implementation of CNodes

#include "stdafx.h"
#include "Nodes.h"
#include "Node.h"

// CNodes

STDMETHODIMP CNodes::InterfaceSupportsErrorInfo(REFIID riid)
{
	static const IID* arr[] = 
	{
		&IID_INodes
	};

	for (int i=0; i < sizeof(arr) / sizeof(arr[0]); i++)
	{
		if (InlineIsEqualGUID(*arr[i],riid))
			return S_OK;
	}
	return S_FALSE;
}

STDMETHODIMP CNodes::get__NewEnum(IUnknown** pVal)
{
	// TODO: Add your implementation code here

	return S_OK;
}

STDMETHODIMP CNodes::get_Item(VARIANT* pVal)
{
	_variant_t index = *pVal;

	m_spRS->MoveFirst();

	if (index.vt == VT_BSTR)	//by name
	{
		BSTR name = index.bstrVal;
		_bstr_t nodeName = m_spRS->Fields->Item[L"Name"]->Value.Detach().bstrVal;
		while(!m_spRS->adoEOF)
		{
			if (nodeName == _bstr_t(name))
			{
				break;
			}
			m_spRS->MoveNext();
		}
		Error(L"Not this node");
		return E_FAIL;
	}
	else
	{
		long pos = index;
		
		if (m_spRS->RecordCount < pos)
		{
			Error(L"Out of index!");
			return E_FAIL;
		}
		m_spRS->Move(pos);			
		
		ADODB::_RecordsetPtr spRSNew = m_spRS->Clone(ADODB::adLockUnspecified);
		spRSNew->AbsolutePosition = m_spRS->AbsolutePosition;
		spRSNew.AddRef();



	}

	// TODO: Add your implementation code here

	return S_OK;
}

STDMETHODIMP CNodes::get_Count(long* pVal)
{
	*pVal = m_spRS->RecordCount;
	return S_OK;
}

